package com.yic.module.mes.api.report;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.yic.module.mes.api.report.dto.ReportRespDTO;
import com.yic.module.mes.api.report.dto.ReportUpdateReqDTO;
import com.yic.module.mes.convert.report.ReportConvert;
import com.yic.module.mes.dal.dataobject.report.ReportDO;
import com.yic.module.mes.service.report.ReportService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @Author: Ljx
 * @createTime: 2023年12月26日 13:37:03
 * @version: v1.0.0
 * @Description: 报工数据API实现
 */
@Service
public class ReportApiImpl implements ReportApi{

    @Resource
    private ReportService reportService;

    @Override
    public List<ReportRespDTO> getReportList(Collection<Long> ids) {
        if (CollectionUtil.isEmpty(ids)) {
            return Collections.emptyList();
        }
        List<ReportDO> reportList = reportService.getReportList(ids);
        return ReportConvert.INSTANCE.convertList03(reportList);
    }

    @Override
    public void batchUpdateReport(Collection<ReportUpdateReqDTO> list) {
        if (CollectionUtil.isNotEmpty(list)) {
            List<ReportDO> reportList = ReportConvert.INSTANCE.convertList04(list);
            reportService.batchUpdateReport(reportList);
        }
    }

    @Override
    public List<ReportRespDTO> getReportList(Long factoryId, Long workshopId, LocalDateTime[] timeArr) {
        List<ReportDO> reportList = reportService.getReportList(factoryId, workshopId, timeArr);
        return ReportConvert.INSTANCE.convertList03(reportList);
    }

    @Override
    public void updateReportByErpInId(Long erpProduceInId) {
        if (ObjectUtil.isNotEmpty(erpProduceInId)) {
            reportService.updateReportByErpInId(erpProduceInId);
        }
    }
}
